<template>
    <div class="cascader">
      <el-cascader
        v-model="value"
        :options="jobList"
        :props="props"
        placeholder="请点击选择" 
        :clearable="true"
      ></el-cascader>
    </div>
</template>

<script>
  import { fetchTreeList } from '@/api/web/dictionary'
    export default {
      watch:{
        value(newVal){
          this.$emit('childByValue', newVal)
        }
      },
      data(){
        return{
          value:[],
          jobList:[],
          props:{
            value: 'id',
            label:'name',
            children: 'children'
          }
        }
      },
      methods:{
        editBackfill (el) {
          fetchTreeList('posttype').then(res => {
            this.jobList = res.data
            this.jobList.map(item => {
              item.children.map(citem => {
                if (citem.id === el) {
                  this.value = [item.id, citem.id]
                }
              })
            })
          })
        }
      },
      created(){
        if (this.$route.path != '/position/edit') {
          fetchTreeList('posttype').then(res => {
            this.jobList = res.data
          })
        }
      }
    }
</script>

<style scoped>

</style>
